package com.tecent.chat.actvity;

import android.content.IntentFilter;
import android.os.Bundle;
import android.util.Log;

import androidx.appcompat.app.AppCompatActivity;

import com.tecent.chat.broadcast.ForceOfflineReceiver;
import com.tecent.chat.data.ActivityList;

public abstract class BaseActivity extends AppCompatActivity {

    ForceOfflineReceiver receiver;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        Log.v("base", getClass().getSimpleName());
        ActivityList.add(this);
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        ActivityList.remove(this);
    }

    @Override
    protected void onResume() {
        super.onResume();
        IntentFilter intentFilter = new IntentFilter();
        intentFilter.addAction("com.tecent.chat.FORCE_OFFLINE");
        receiver = new ForceOfflineReceiver();
        registerReceiver(receiver, intentFilter);
    }

    @Override
    protected void onPause() {
        super.onPause();
        if(receiver != null){
            unregisterReceiver(receiver);
            receiver = null;
        }
    }
}